Atomig: generic and convenient std
atomics
Offers Atomic<T>
that can be used with primitive and custom types.
However, it only works with types that can actually use atomic operations: a lock-based fallback for other types is not used!
This crate is based on std
's atomics and therefore does not contain any unsafe
code!
This crate also does not have any dependencies by default.
If you enable the serde
feature, then this crate will depend on serde
and Serialize
/ Deserialize
will be
implemented for Atomic<T>
when appropriate, using sequentially-consistent ordering.
Simple example with primitive types:
use ;
let x = new; // `Atomic<i32>`
x.store;
This works with almost all primitive types, including f32
, f64
and char
,
but also with types like std::ptr::NonNull
and std::num::NonZero
.
You can automatically derive Atom
for your own enum or struct types to use them in Atomic<T>
.
There are some limitations, however.
// Requires the 'derive' feature:
// atomig = { version = "_", features = ["derive"] }
use ;
let animal = new;
animal.store;
;
let port = new;
port.store;
For more examples and information see the documentation.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.